if CLIENT then

	CreateClientConVar("stats_time_display", "1", true, false)
	
	function PlayerInitialSpawn(uh)
	local pl = LocalPlayer()
	local ttime = uh:ReadLong()
	pl.TimeSpent = math.floor(CurTime())
	pl.TotalTimeSpent = math.floor((CurTime()) + ttime)
	end
	usermessage.Hook("PlayerInitialSpawn",PlayerInitialSpawn)
	
	--Lemming did this
function HUDPaint()
	if(GetConVarNumber("stats_time_display") >= 1) then
	
	if(!LocalPlayer().TimeSpent || !LocalPlayer().TotalTimeSpent) then return end
	
	// Session time first
	
	local STime = CurTime() - LocalPlayer().TimeSpent
	
	local SHours = tostring(math.floor(STime / (60 * 60)))
	local SMinutes = tostring(math.floor(STime / 60) - (SHours * 60))
	local SSeconds = tostring(math.floor(STime) - (SMinutes * 60) - (SHours * (60 * 60)))
	
	// Total Time
	
	local TTime = (LocalPlayer().TotalTimeSpent + STime) --TIME TO BUTCHER THIS SHIT ~Eb
	local TDays = tostring(math.floor(TTime / (60 * 60 * 24)))
	local THours = tostring(math.floor(TTime / (60 * 60)) - (TDays * 24))
	local TMinutes = tostring(math.floor(TTime / 60) - (TDays * (24 * 60)) - (THours * 60))
	local TSeconds = tostring(math.floor(TTime) - (TDays * (24 * 60 * 60)) - (THours * 60 * 60) - (TMinutes * 60))
	--Yesss~ now total time updates in real time! :3 ~Eb
	// Draw this shit
	
	local Offs = 0
	
	if(GetConVarNumber("stats_time_display") >= 2) then
		local OpenTime = 56
		local CloseTime = 3
		local DistFromEdge = 200
		
		local Proceed = false
		
		if(GetConVarNumber("stats_time_display") == 2) then
			Proceed = (tonumber(SSeconds) >= OpenTime || tonumber(SSeconds) <= CloseTime)
		end
		
		if(Proceed) then
			if(tonumber(SSeconds) >= OpenTime) then
			
				if(tonumber(SSeconds) < OpenTime + 1) then
					local Time = STime
					Offs = Time - math.floor(Time)
					Offs = (math.Clamp(Offs, 0, 1) - 1) * DistFromEdge
				else Offs = 0 end
				
			elseif(tonumber(SSeconds) <= CloseTime) then
			
				if(tonumber(SSeconds) > CloseTime - 1) then
					local Time = STime
					Offs = Time - math.floor(Time)
					Offs = math.Clamp(Offs, 0, 1) * -DistFromEdge
				else Offs = 0 end
				
			else Offs = -DistFromEdge end
		else Offs = -DistFromEdge end
	end
	
	draw.RoundedBox(6, Offs + 43, 43, 64, 44, Color(60, 80, 100, 210))
	draw.RoundedBox(4, Offs + 45, 45, 60, 40, Color(160, 170, 180, 210))
	
	draw.SimpleText(TDays.."d, "..THours..":"..TMinutes, "ScoreboardText", Offs + 75, 74, Color(60,80,100,210), 1, 1)
	
	draw.SimpleText(SHours..":"..SMinutes..":"..SSeconds, "ScoreboardText", Offs + 75, 56, Color(60,80,100,210), 1, 1)
	end
end 

hook.Add("HUDPaint", "TimePlayed", HUDPaint);

end
